import React from "react";
import { RouteObject, Navigate } from "react-router-dom";
import lazyLoad from "./lazyLoad";

import Layout from "../views/layout";
// import Home from "../views/home";
// import User from "../views/user";
// import Login from "../views/login";
// import Error from "../views/error/404";

const router_item: Array<object> = [
  // 重定向layout
  {
    path: "/",
    label: "首页",
    key: "/",
    element: <Navigate to="/layout" replace={true} />,
  },
  // 登录页
  {
    path: "/login",
    label: "登录",
    key: "login",
    // element: <Login />,
    element: lazyLoad(React.lazy(() => import("../views/login"))),
    meta: {
      // 不需要权限
      unwantedAuth: true,
      title: "登录页",
      key: "login",
    },
  },
  // 基本路由配置
  {
    path: "/layout",
    label: "控制台",
    key: "layout",
    element: <Layout />,
    // element: lazyLoad(React.lazy(() => import("../views/layout"))),
    children: [
      {
        path: "user",
        label: "用户",
        key: "user",
        // element: <User />,
        element: lazyLoad(React.lazy(() => import("../views/user"))),
        index: 1,
        children: [
          {
            path: "user1",
            label: "用户1",
            key: "user1",
            // element: <User />,
            element: lazyLoad(React.lazy(() => import("../views/user"))),
          },
          {
            path: "home1",
            label: "首页1",
            key: "home1",
            element: lazyLoad(React.lazy(() => import("../views/home"))),
          },
        ],
      },
      {
        path: "home",
        label: "首页",
        key: "home",
        element: lazyLoad(React.lazy(() => import("../views/home"))),
      },
    ],
  },
  {
    path: "/404",
    label: "404",
    key: "404",
    // element: <Error />,
    element: lazyLoad(React.lazy(() => import("../views/error/404"))),
    meta: {
      // 不需要权限
      unwantedAuth: true,
      title: "404",
      key: "error",
    },
  },
  {
    path: "*",
    element: <Navigate to="/404" />,
  },
];
const routes: RouteObject[] = router_item;

export default routes;
